PLAYER := PlayerExe
GOALIE := GoalieExe
COACH := CoachExe
OUTPUT := Output

COMMON_SRCS := \
	Common/Interact.cpp Common/Main.cpp Common/World/Vector.cpp \
	Common/Support/Debug.cpp Common/Protocol/CommandGen.cpp \
	Common/Protocol/Parser.cpp Common/Protocol/CharString.cpp \
	Common/Protocol/ServerSocket.cpp Common/Protocol/ParseStrings.cpp \
  Player/Formation.cpp
COMMON_P_AND_G_SRCS := \
	Player/PlayerKernel.cpp \
	Player/World/Ball.cpp Player/World/Movable.cpp \
	Player/World/Myself.cpp Player/World/Params.cpp \
	Player/World/Player.cpp Player/World/State.cpp \
	Player/World/Variables.cpp Player/World/World.cpp \
	Player/ModuleManager/ModuleManager.cpp Player/ModuleManager/DataStorage.cpp \
	Player/ModuleManager/Behaviours/TurnNeckToAuxBehaviour.cpp \
	Player/ModuleManager/Behaviours/AlignNeckBehaviour.cpp \
	Player/ModuleManager/Behaviours/RunToPositionBehaviour.cpp \
	Player/ModuleManager/Behaviours/TurnNeckToBehaviour.cpp \
	Player/ModuleManager/Behaviours/TurnToBehaviour.cpp \
	Player/ModuleManager/Behaviours/SayBehaviour.cpp \
	Player/ModuleManager/Behaviours/TackleBehaviour.cpp \
	Player/ModuleManager/Behaviours/MoveBehaviour.cpp \
	Player/ModuleManager/Behaviours/NearKickBehaviour.cpp \
	Player/ModuleManager/Behaviours/PassBallToBehaviour.cpp \
	Player/ModuleManager/Behaviours/KickBehaviour.cpp \
	Player/ModuleManager/Behaviours/OutPlayOpponentBehaviour.cpp \
	Player/ModuleManager/Behaviours/DribbleBehaviour.cpp \
	Player/ModuleManager/Behaviours/UnblockMyselfBehaviour.cpp \
	Player/ModuleManager/Behaviours/InterceptBallBehaviour.cpp \
	Player/ModuleManager/Behaviours/OffsideLineBreachBehaviour.cpp \
	Player/ModuleManager/Behaviours/PassToStrategicPositionBehaviour.cpp \
	Player/ModuleManager/Behaviours/TheirFreeKickBehaviour.cpp \
	Player/ModuleManager/Behaviours/TheirKickInBehaviour.cpp \
	Player/ModuleManager/Behaviours/PassToRandomUmbrellaPositionBehaviour.cpp \
	Player/ModuleManager/Behaviours/OurKickOffBehaviour.cpp \
	Player/ModuleManager/Behaviours/CrossPassToGoalBehaviour.cpp \
	Player/ModuleManager/Behaviours/PassBallNearToGoalieBehaviour.cpp \
	Player/ModuleManager/Behaviours/PassBallToNormalPassPositionBehaviour.cpp \
	Player/ModuleManager/Behaviours/OurCornerKickWithoutBallBehavior.cpp \
	Player/ModuleManager/Behaviours/OurFreeKickWithoutBallBehaviour.cpp \
	Player/ModuleManager/Behaviours/MoveToAnyKickPositionWithoutBallBehavior.cpp \
	Player/ModuleManager/Behaviours/StartPlayOnByPassToOurPlayerBehaviour.cpp \
	Player/ModuleManager/Behaviours/OurKickInBehaviour.cpp \
	Player/ModuleManager/Behaviours/MoveToAnyKickPositionWithoutBallBehavior.cpp \
	Player/ModuleManager/Behaviours/ScanBehaviour.cpp \
	Player/ModuleManager/Behaviours/KickToGoalBehaviour.cpp \
	Player/ModuleManager/Behaviours/PlayOnWithBallBehaviour.cpp \
	Player/ModuleManager/Behaviours/DribbleBehaviour.cpp \
	Player/ModuleManager/Behaviours/ActBehaviour.cpp \
	Player/ModuleManager/Behaviours/PlayOnBehaviour.cpp \
	Player/ModuleManager/Behaviours/PlayOffBehaviour.cpp \
	Player/ModuleManager/Behaviours/LeaderShipBehaviour.cpp \
	Player/ModuleManager/Behaviours/WithBallBehaviour.cpp \
	Player/ModuleManager/Behaviours/WithoutBallBehaviour.cpp \
	Player/ModuleManager/Behaviours/SearchForBallBehaviour.cpp \
	Player/ModuleManager/Behaviours/OurCornerKickBehaviour.cpp \
	Player/ModuleManager/Behaviours/OurFreeKickBehaviour.cpp \
	Player/ModuleManager/Behaviours/OurIndividualFreeKickBehaviour.cpp \
	Player/ModuleManager/Behaviours/OurKickInWithoutBallBehavior.cpp \
	Player/ModuleManager/Behaviours/PlayOnWithoutBallBehaviour.cpp \
	Player/ModuleManager/Behaviours/ActTestBehaviour.cpp \
	Player/ModuleManager/EventHandlers.cpp \
	Player/ModuleManager/UttpBehaviourTestCase.cpp \
	Player/ModuleManager/Behaviours/PlayerBehaviourTests/NearKickTestCase.cpp \
	Player/ModuleManager/Behaviours/PlayerBehaviourTests/PassBallToTestCase.cpp \
	Player/ModuleManager/Behaviours/PlayerBehaviourTests/RunToPositionTestCase.cpp \
	Player/ModuleManager/Behaviours/PlayerBehaviourTests/TurnNeckToAuxTestCase.cpp \
	Player/ModuleManager/Behaviours/PlayerBehaviourTests/TurnToTestCase.cpp
EVALUATING_SRCS := \
	Evaluating/EvaluatingPlayerList.cpp Evaluating/EvaluatingPanesMap.cpp \
	Evaluating/EvaluatingPane.cpp Evaluating/EvaluatingPlayer.cpp
PLAYER_SRCS :=
GOALIE_SRCS := \
	Player/ModuleManager/Behaviours/GoalieBehaviours/CatchBehaviour.cpp \
	Player/ModuleManager/Behaviours/GoalieBehaviours/BallHeadingOnGoalBehaviour.cpp \
	Player/ModuleManager/Behaviours/GoalieBehaviours/BallUnknownBehaviour.cpp \
	Player/ModuleManager/Behaviours/GoalieBehaviours/DashBehaviour.cpp \
	Player/ModuleManager/Behaviours/GoalieBehaviours/DefenseLineBehaviour.cpp \
	Player/ModuleManager/Behaviours/GoalieBehaviours/KickOffBehaviour.cpp \
	Player/ModuleManager/Behaviours/GoalieBehaviours/PassNearGoalBehaviour.cpp \
	Player/ModuleManager/Behaviours/GoalieBehaviours/PlayGoalieBehaviour.cpp	
COACH_SRCS := Coach/CoachKernel.cpp Coach/World/CoachMemory.cpp \
	Coach/CoachSynchronization.cpp Coach/CoachAnalyser.cpp

PLAYER_CFLAGS =
GOALIE_CFLAGS = -DGOALIE
COACH_CFLAGS = -DCOACH

CXX         = g++
LD          = g++

CPPFLAGS    +=
CFLAGS      += -O2 -I.
CXXFLAGS    +=
LDFLAGS     += -Wall -lm

ifdef NDEBUG

CPPFLAGS    +=
CFLAGS      += -g -DDEBUG 
CXXFLAGS    +=
LDFLAGS     +=

else

CPPFLAGS    +=
CFLAGS      +=
CXXFLAGS    +=
LDFLAGS     +=

endif

################################################################################

PLAYER_OBJS := $(sort $(addprefix $(OUTPUT)/$(PLAYER)/, $(addsuffix .o, $(basename $(COMMON_SRCS) $(COMMON_P_AND_G_SRCS) $(EVALUATING_SRCS) $(PLAYER_SRCS)))))
GOALIE_OBJS := $(sort $(addprefix $(OUTPUT)/$(GOALIE)/, $(addsuffix .o, $(basename $(COMMON_SRCS) $(COMMON_P_AND_G_SRCS) $(EVALUATING_SRCS) $(GOALIE_SRCS)))))
COACH_OBJS := $(sort $(addprefix $(OUTPUT)/$(COACH)/, $(addsuffix .o, $(basename $(COMMON_SRCS) $(COACH_SRCS)))))

$(OUTPUT)/$(PLAYER)/%.o: %.cpp
	echo -n "$(PLAYER): Compiling $<... "
	mkdir -p $(dir $@)
	$(CXX) -c $(CPPFLAGS) $(CFLAGS) $(CXXFLAGS) $(PLAYER_CFLAGS) -o $@ $<
	echo "done"

$(OUTPUT)/$(GOALIE)/%.o: %.cpp
	echo -n "$(GOALIE): Compiling $<... "
	mkdir -p $(dir $@)
	$(CXX) -c $(CPPFLAGS) $(CFLAGS) $(CXXFLAGS) $(GOALIE_CFLAGS) -o $@ $<
	echo "done"

$(OUTPUT)/$(COACH)/%.o: %.cpp
	echo -n "$(COACH): Compiling $<... "
	mkdir -p $(dir $@)
	$(CXX) -c $(CPPFLAGS) $(CFLAGS) $(CXXFLAGS) $(COACH_CFLAGS) -o $@ $<
	echo "done"

.PHONY: all clean depclean

all: $(OUTPUT)/$(PLAYER)/$(PLAYER) $(OUTPUT)/$(GOALIE)/$(GOALIE) $(OUTPUT)/$(COACH)/$(COACH)

$(OUTPUT)/$(PLAYER)/$(PLAYER): $(PLAYER_OBJS)
	echo -n "$(PLAYER): Linking $@... "
	mkdir -p $(dir $@)
	$(LD) $(CFLAGS) $(CXXFLAGS) $(PLAYER_CFLAGS) -o $@ $^ $(LDFLAGS)
	echo "done"
	
$(OUTPUT)/$(GOALIE)/$(GOALIE): $(GOALIE_OBJS)
	echo -n "$(GOALIE): Linking $@... "
	mkdir -p $(dir $@)
	$(LD) $(CFLAGS) $(CXXFLAGS) $(GOALIE_CFLAGS) -o $@ $^ $(LDFLAGS)
	echo "done"
	
$(OUTPUT)/$(COACH)/$(COACH): $(COACH_OBJS)
	echo -n "$(COACH): Linking $@... "
	mkdir -p $(dir $@)
	$(LD) $(CFLAGS) $(CXXFLAGS) $(COACH_CFLAGS) -o $@ $^ $(LDFLAGS)
	echo "done"
	
clean:
	echo -n "Cleaning up... "
	-rm -rf $(OUTPUT)
	echo done

ifndef LOUD
.SILENT:
endif
